package jjn.round2;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Jjn
 * @since 2023/5/11 16:22
 */
public class Offer61_Straight {
    public boolean isStraight(int[] nums) {
        int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
        Set<Integer> added = new HashSet<>();
        for (int num : nums) {
            if (num == 0) {
                continue;
            }
            if (added.contains(num)) {
                return false;
            }
            added.add(num);
            max = Math.max(max, num);
            min = Math.min(min, num);
        }
        return max - min <= 4;
    }
}
